if (window.plus) {
    ready();
} else {
    document.addEventListener('plusready', ready, false);
}

$(function(){
  if(AGENT_CLIENT.WEB){
    ready();
  } 
})

function ready() {

    var _thisPage = null;
    var _user = null;
    var _phone = "";
    var _backurl = getUrlParam("backurl");

    var editphonePage = function () {
        this.init();
    };

    editphonePage.prototype = {

        init: function () {
            this.initData();
            this.bindEvent();
        },
        initData: function () {
            //获取用户信息
            _user = getLocalStorage(STORAGE_MANAGER.user);
            if (!_user) {
                redirect("login.html");
                return false;
            }
            //获取手机号
            _phone = getUrlParam("phone");
            $("#phone").html(_phone).attr("tip", _user.id);

        },
        bindEvent: function () {
            //回退
            $("#back").on("click", function () {
                back();
            });

            //点击获取验证码
            $("#getVcode").on("click", function () {
				change_code(this, $("#phone"), SMS_TYPE.safety);               
            });

            $("#nextStep").on("click", function () {
              if('' == $("#vcode").val()){
                  $.alert("请填写验证码");
                  return false;                  	
              }
              if(!isVCode($("#vcode").val())){
                  $.alert("请填写正确的验证码");
                  return false;              	
              } 
              var redirectUrl = "setphone.html?type=edit";
              if(_backurl){
              	redirectUrl += "&backurl=" + _backurl;
              }
			  redirect(redirectUrl);
            });

        }
    };

    _thisPage = new editphonePage();
}
